package cn.com.dhcc.turbo.web.controller.registry;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dhcc.app.core.base.BaseController;
import cn.com.dhcc.app.core.exception.NiceException;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.annotation.TurboMenu;
import cn.com.dhcc.app.pub.core.annotation.TurboMenu.LEAF_MENU;
import cn.com.dhcc.turbo.entity.exch.GapUserConf;
import cn.com.dhcc.turbo.entity.registry.NodeInfo;
import cn.com.dhcc.turbo.service.registry.BaseInfoService;
import cn.com.dhcc.turbo.service.registry.GapUserConfService;

@Controller
@RequestMapping("/registry")
@TurboMenu(belongToMenu=LEAF_MENU.UNCM_STRUC_MONITOR_RECV)
public class GapUserConfDataController extends BaseController {
	@SuppressWarnings("deprecation")
	private static Logger logger = Log.getExistLogger(LOGTYPE.SAI);

	@Autowired
	private GapUserConfService gapUserService;
	@Autowired
	private BaseInfoService baseInfoService;
	
	@RequestMapping(value = "/gap_user_conf_list")
	public String list(Model model) {
		    try {
				NodeInfo nodeInfo=baseInfoService.getCurrentNodeInfo();
				List<GapUserConf> getUserConf=gapUserService.getUserConfList();
				String gapName=nodeInfo.getNodeName();
				model.addAttribute("gapName", gapName);
				model.addAttribute("getUserConf", getUserConf);
			} catch (ServiceException e) {
				// TODO Auto-generated catch block
				logger.error(e);
			} catch (NiceException e) {
				// TODO Auto-generated catch block
				logger.error(e);
			}
			return "registry/gap_user_conf_list";
	};
	/**
	 * 获取网闸所有者节点编码
	 * getOwnerConfList
	 * @return
	 */
	
	@RequestMapping(value = "/ga_data_list")
	@ResponseBody
	public Object gapDataGet(){
		try {
			return gapUserService.getUserConfList();
		} catch (NiceException e) {
			logger.error("获取网闸所有者节点编码失败",e);
		}
		return null;
	}
	
	
	/**
	 * 更新网闸所有者节点编码
	 * 
	 * @return
	 */
	@RequestMapping(value = "/ga_data_insertOrUpdate")
	@ResponseBody
	public Object insertOrUpdate(String gapOwner,String id){
		String msg="保存成功";
		try {
			
			gapUserService.updateDefaultGap(gapOwner);
			return jsonSuccessResult(msg);
		} catch (ServiceException e) {
			logger.error("更新网闸所有者节点编码",e);
			return jsonFailResult("保存失败");
		}
		
	}
	
	

}
